package com.xq.tmall.service.impl;

import com.xq.tmall.dao.BusinessMapper;
import com.xq.tmall.entity.Business;
import com.xq.tmall.service.BusinessService;
import com.xq.tmall.util.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("businessService")
public class BusinessServiceImpl implements BusinessService {

    private BusinessMapper businessMapper;
    @Resource(name = "businessMapper")
    public void setBusinessMapper(BusinessMapper businessMapper) {
        this.businessMapper = businessMapper;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public boolean add(Business business) {
        return businessMapper.insertOne(business)>0;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public boolean update(Business business) {
        return businessMapper.updateOne(business)>0;
    }

    @Override
    public List<Business> getList(String business_name, PageUtil pageUtil) {
        return businessMapper.select(business_name,pageUtil);
    }

    @Override
    public Business get(String business_name,Integer business_id) {
        return businessMapper.selectOne(business_name,business_id);
    }

    @Override
    public Business login(String business_name, String business_password) {
        return businessMapper.selectByLogin(business_name,business_password);
    }

    @Override
    public Integer getTotal(String business_name) {
        return businessMapper.selectTotal(business_name);
    }
}
